package com.sanyue.springboot.controller;

import com.sanyue.springboot.exception.AccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @author: Guan
 **/
@Controller
public class MyErrorController {
    @GetMapping("/error")
    public String ErrorTest(){
        int i = 10 / 0;
        return "manage";
    }

    //配置Post方式接收Get请求 客户端错误4开头
    @PostMapping("/error2")
    public String ErrorTest2(){
        return "manage";
    }

    //模拟自定义异常AccessException
    @GetMapping("/err3")
    public String ErrorTest3(String name){
        //如果用户的名字不是Tom，则无法访问
        if(!"Tom".equals(name)){
            // throw new AccessException();
            throw new AccessException("自定义的异常");
        }
        //因为没有经过Controller的toManage请求，所以没有模拟的数据
        // return "manage";
        return "redirect:/ToManage";
    }
}
